import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'

Vue.use(Vuex)

const modulesFiles = require.context('./modules', true, /\.js$/)

const modules = modulesFiles.keys().reduce((files, filesPath) => {
  const filesName = filesPath.replace(/^\.\/(.*)\.\w+$/, '$1')
  const value = modulesFiles(filesPath)
  files[filesName] = value.default
  return files
}, {})

//Vuex  引入modules路径下的所有文件模块,引入getters模块
const store = new Vuex.Store({
  modules,
  getters
})

export default store
